package com.gscitysfy.cus.drain.modules.command.convert;

import com.gscitysfy.cus.drain.modules.command.dto.InstructCarDto;
import com.gscitysfy.cus.drain.modules.command.dto.InstructWarehouseDto;
import com.gscitysfy.cus.drain.modules.command.dto.ResourceDispatchDto;
import com.gscitysfy.cus.drain.modules.command.entity.InstructCar;
import com.gscitysfy.cus.drain.modules.command.entity.InstructWarehouse;
import com.gscitysfy.cus.drain.modules.command.service.IInstructCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Author jiang_wen
 * @Date 2022/10/24 19:04
 * @Description TODO
 */
@Component
public class InstructWarehouseConvert {

    @Autowired
    @Lazy
    private IInstructCarService iInstructCarService;

    public InstructWarehouse toEntity(InstructWarehouse instructWarehouse, InstructWarehouseDto instructWarehouseDto) {
        instructWarehouse.setDangerSituationId(instructWarehouseDto.getDangerSituationId());
        instructWarehouse.setWarehouseId(instructWarehouseDto.getWarehouseId());
        instructWarehouse.setMessageTemplate(instructWarehouseDto.getMessageTemplate());
        instructWarehouse.setStatus(instructWarehouseDto.getStatus());
        return instructWarehouse;
    }

    public List<InstructWarehouse> toEntityList(ResourceDispatchDto resourceDispatchDto) {
        List<InstructWarehouse> instructWarehouseList = new ArrayList<>();
        List<InstructWarehouseDto> instructWarehouseDtoListList = resourceDispatchDto.getInstructWarehouseDtoList();
        //过滤之前筛选的仓库
//        Set<Long> selectedCarId = InstructCarService.fetchByDangerSituation(resourceDispatchDto.getDangerSituationId())
//                .stream()
//                .map(InstructCar::getCarId)
//                .collect(Collecitors.toSet());
//        List<InstructCarDto> filterInstructCarDtoList = instructCarDtoList
//                .stream()
//                .filter(c -> !selectedCarId.contains(c.getCarId()))
//                .collect(Collectors.toList());

        InstructWarehouse instructWarehouse;
        for (InstructWarehouseDto instructWarehouseDto : instructWarehouseDtoListList) {
            instructWarehouse = new InstructWarehouse();
            instructWarehouseDto.setStatus("PENDING");
            instructWarehouseDto.setDangerSituationId(resourceDispatchDto.getDangerSituationId());
            instructWarehouseList.add(toEntity(instructWarehouse, instructWarehouseDto));
        }
        return instructWarehouseList;
    }
}
